<HTML>
<!-- =====================================================================

  File:      AlsoBought.htm for Adventure Works Cycles Storefront Sample
  Summary:   Self-documentation for application
  Date:	     June 16, 2003

=====================================================================

  This file is part of the Microsoft SQL Server Code Samples.
  Copyright (C) Microsoft Corporation.  All rights reserved.

This source code is intended only as a supplement to Microsoft
Development Tools and/or on-line documentation.  See these other
materials for detailed information regarding Microsoft code samples.

THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

======================================================= -->
    <head>
        <title>Adventure Works Cycles Store Documentation</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <BODY>
        <h1>
        AlsoBought User Control
        </h1>
        <P>
            <strong>Description:</strong>&nbsp;The AlsoBought user control displays a list of the 5 other products most
        often purchased by customers who also purchased a specified product.&nbsp;
        </P>
        <P>
            <A href="UserControls.htm">
                <STRONG>Click here to learn more about what user controls are and how they are used within ASP.NET Web Applications</STRONG></A>
        </P>
        <P>
            <strong>Implementation Notes:&nbsp;</strong>
            &nbsp;The AlsoBought control is used in the
            <A href="productdetails_aspx.htm">
            ProductDetails.aspx</A>&nbsp;page.
        <p>
        The AlsoBought user control exposes a single public field -- ProductID -- at
        the top of the file.&nbsp; This enables consumers of the AlsoBought user
        control (like the ProductDetails.aspx page) to set the ProductID of the
        AlsoBought product either programmatically or declaratively (via a tag
        attribute).&nbsp; Note that only those fields, properties and methods that have
        a public accessor declaration can be externally accessed in this way.&nbsp; For
        example, the Page_Load event handler does not have a public accessor keyword
        before it, and therefore can not be called from the ProductDetails.aspx page.
        <p>
        The AlsoBought user control logic is encapsulated entirely within 
        its&nbsp;<strong>Page_Load</strong>&nbsp;event handler.&nbsp; This event handler is called when a page containing
        the user control is accessed by a browser client.&nbsp;
        <P>
            <strong>Page_Load Event Handler:&nbsp;</strong>
            &nbsp;The Page_Load event handler creates an instance of the ProductDB class
            and calls its GetProductsAlsoPurchased method, passing it the product ID. This
            method internally uses the
            <A href="usp_CustomerAlsoBought.htm">usp_CustomerAlsoBought</A>
        &nbsp;stored procedure to fetch the product&nbsp;information from the Adventure Works Cycles database.&nbsp;
        <p>
        The product collection is displayed using a templated &lt;asp:Repeater&gt;
        server control.&nbsp; As used in this user control, the Repeater server control
        contains three user-defined templates -- HeaderTemplate, ItemTemplate and
        FooterTemplate -- that describe how the list should look.&nbsp; The
        ItemTemplate defines how the bound data is displayed; the HeaderTemplate
        defines HTML that is emitted at the beginning of the list;&nbsp;and the
        FooterTemplate defines HTML that is emitted at the end of the list.
        <P>
        The data values returned from the ProductsDB.GetProductsAlsoPurchased() method are populated into the Repeater by setting 
        its Datasource property, and then calling its&nbsp;<strong>DataBind()</strong>&nbsp;method.&nbsp; When DataBind() 
        is called, the Repeater will render its
        HeaderTemplate, then iterate over the DataSource and render a copy of the
        ItemTemplate for each row, populating it data from the row.&nbsp;
        Finally,&nbsp;the Repeater&nbsp;will render its FooterTemplate.&nbsp;
        <P>
            <B>Peformance Notes:</B>
            <UL>
                <LI>
                    Unlike the
                    <A href="_popularitems_ascx.htm">
                    PopularItems</A>
                    &nbsp;user control, whose purpose and logic&nbsp;are very similar, the
                    AlsoBought user control does not cache the results of the
                    ProductsDB.GetProductsAlsoPurchased() method.&nbsp; This is because the
                    AlsoBought user control is currently only used from the
                    <A href="productdetails_aspx.htm">
                    ProductDetails.aspx</A>
                &nbsp;page, which itself uses output caching.&nbsp; As such, the results
                generated by the AlsoBought user control are already cached by the containing page.
            </UL>
    </BODY>
</HTML>

